###
# tl_contribMapper
#
# The script automates the process of creating contribution mapsfor rendering or
#  
# Author: Marcus Olofsson
# Maya version: 2011-x64
# Date: 2011/03/15
###
import pymel.core as pm
import maya.mel as mel

def tl_contribMapper():
    objList = pm.ls(sl=True)

    currentLayer = pm.editRenderLayerGlobals(q=1, crl=1)
    for obj in objList:
        contMap = pm.createNode('passContributionMap', ss=True)
        pm.rename(contMap, obj+'_contMap')
        pm.connectAttr(currentLayer+'.passContributionMap', contMap+'.owner', na=True)
        mel.eval('renderLayerEditorAlterObjectsInContMap "RenderLayerTab" '+str(currentLayer)+' '+str(contMap)+' 1 ')
        renderPS = pm.createNode("renderPass", ss=True)
        pm.rename(renderPS, ("a_"+obj))
        mel.eval('applyAttrPreset '+renderPS+' "C:/Program Files/Autodesk/Maya2011/presets/attrPresets/renderPass/beauty.mel" 1')
        pm.connectAttr(currentLayer+".renderPass", renderPS+".owner", na=True)
        pm.connectAttr(renderPS+'.message', contMap+'.renderPass', na=True)
